import projectInfo from '../projectInfo.js'
export default link => {
	var linkUrl;
	if (link.dataType == 1) {
		// 商家分两种,景区详情页/其他商家详情页
		if (link.linkPoiType == 'lyjd') {
			linkUrl = projectInfo.jqDetailUrl + '?id=' + link.linkStoreNo
		} else {
			linkUrl = projectInfo.storeDetailUrl + '?id=' + link.linkStoreNo
		}
	} else if (link.dataType == 2) {
		// 商品分两种,非线路详情页/线路详情页
		if (link.linkPoiType == '878') {
			linkUrl = projectInfo.lineDetailUrl + '?id=' + link.linkId;
		} else {
			linkUrl = projectInfo.goodDetailUrl + '?id=' + link.linkId;
		}
	} else if (link.dataType == 3) {
		// 资讯详情页
		linkUrl = projectInfo.newsDetailUrl + '?id=' + link.linkId
	} else if (link.dataType == 99) {
		// 外链:https开头的链接/模块化页面/拨打电话/跳转小程序/其他原生页面
		if (/^https?:\/\//.test(link.linkUrl)) {
			linkUrl = '/views/common/webView?url=' + encodeURIComponent(link.linkUrl);
		}else if(/^pageId=/.test(link.linkUrl)){
			var pageIdInfo = link.linkUrl.split('pageId=')[1].split('?')
			var pageId = pageIdInfo[0],pageIdPara = pageIdInfo[1] || ''
			linkUrl = '/views/singlePage?pageId=' + pageId + '&' + pageIdPara
		} else if (/^phoneCall=/.test(link.linkUrl)) {
			var phoneNumber = link.linkUrl.split('phoneCall=')[1].split('?')[0]
			makePhoneCall(phoneNumber)
			return
		} else if(/^mini=/.test(link.linkUrl)) {
			var miniInfo = link.linkUrl.split('mini=')[1].split(',')
			var miniAppid = miniInfo[0],miniPath = miniInfo[1]
			uni.navigateToMiniProgram({
				appId: miniAppid,
				path: miniPath
			});
			return
		} else {
			linkUrl = link.linkUrl
		}
	} else if (link.dataType == 4) {
		// 资讯列表页
		linkUrl = projectInfo.newsListUrl + '?type=' + link.linkPoiType
	}else{
		uni.showToast({
			title:'跳转规则错误!',
			icon:'none'
		})
		return
	}
	console.log('跳转地址',linkUrl)
	uni.navigateTo({
		url: linkUrl
	});
}
